//
//  RechargeListViewModel.m
//  CBT
//
//  Created by Mr.Zhang on 2018/12/14.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "RechargeListViewModel.h"
#import "UserManager.h"

@implementation RechargeListViewModel

- (instancetype)init
{
    if (self = [super init]) {
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    self.listSuccessObject = [RACSubject subject];
    self.listFailureObject = [RACSubject subject];
}

-(void)exchangeDataWithPage:(NSString *)page
{
    @weakify(self);
    if (self.showListType == 0) {
        [UserManager getRechargeRecordWithUserId:[CBTLocalUserManager sharedInstance].userId coinId:self.coinId page:page block:^(id data, HttpRequestResult result, NSString *msg) {
            if (result == kHttpRequestResultNormal) {
                RechargeRecordModel *model = [RechargeRecordModel mj_objectWithKeyValues:data[@"data"]];
                [self_weak_.listSuccessObject sendNext:model];
            }else{
                [self_weak_.listFailureObject sendNext:nil];
            }
        }];
    }else if(self.showListType == 1){
        [UserManager getInvestRecordWithUserId:[CBTLocalUserManager sharedInstance].userId page:page block:^(id data, HttpRequestResult result, NSString *msg) {
            if (result == kHttpRequestResultNormal) {
                [self_weak_.listSuccessObject sendNext:[RechargeListModel mj_objectWithKeyValues:data[@"data"]]];
            }else{
                [self_weak_.listFailureObject sendNext:nil];
            }
        }];
    }else if(self.showListType == 2){
        [UserManager getDrawRecordListWithUserId:[CBTLocalUserManager sharedInstance].userId page:page block:^(id data, HttpRequestResult result, NSString *msg) {
            if (result == kHttpRequestResultNormal) {
                [self_weak_.listSuccessObject sendNext:[WithdrawListModel mj_objectWithKeyValues:data[@"data"]]];
            }else{
                [self_weak_.listFailureObject sendNext:nil];
            }
        }];
    }else{
        [UserManager getChangeRecordWithUserID:[CBTLocalUserManager sharedInstance].userId coinId:self.coinId page:page block:^(id data, HttpRequestResult result, NSString *msg) {
            if (result == kHttpRequestResultNormal) {
                [self_weak_.listSuccessObject sendNext:[TransferModel mj_objectWithKeyValues:data[@"data"]]];
            }else{
                [self_weak_.listFailureObject sendNext:nil];
            }
        }];
    }
}

@end
